using System;
using EntModApp.EntServices;
using EntModApp.EntServices.Data;

namespace DemoApp.DataAccess 
{
  public partial class DemoAppModelQueryableDataRepository : 
    IQueryableDemoAppModelDataRepository
  {
    public DemoAppModelQueryableDataRepository(DemoAppModelDbContext context)
      : this(context, false)
    {
    }

    public DemoAppModelQueryableDataRepository()
      : this(new DemoAppModelDbContext(), true)
    {
    }

    protected DemoAppModelQueryableDataRepository(DemoAppModelDbContext context, bool ownContext)
    {
      if (context == null) throw new ArgumentNullException();
      Context = context;
      OwnContext = ownContext;
    }

    protected DemoAppModelDbContext Context { get; private set; }
    protected bool OwnContext { get; private set; }

    private IQueryableRoleRepository _Roles;
    public IQueryableRoleRepository Roles
    {
      get { return _Roles ?? (_Roles = new RoleQueryableRepository(Context)); }
    }
		 
    private IQueryableSecurableActionRepository _SecurableActions;
    public IQueryableSecurableActionRepository SecurableActions
    {
      get { return _SecurableActions ?? (_SecurableActions = new SecurableActionQueryableRepository(Context)); }
    }
		 
    private IQueryableUserRepository _Users;
    public IQueryableUserRepository Users
    {
      get { return _Users ?? (_Users = new UserQueryableRepository(Context)); }
    }
		 
    private IQueryablePersonRepository _People;
    public IQueryablePersonRepository People
    {
      get { return _People ?? (_People = new PersonQueryableRepository(Context)); }
    }
		 
    private IQueryableGroupRepository _Groups;
    public IQueryableGroupRepository Groups
    {
      get { return _Groups ?? (_Groups = new GroupQueryableRepository(Context)); }
    }
		 
    private IQueryableSubjectRepository _Subjects;
    public IQueryableSubjectRepository Subjects
    {
      get { return _Subjects ?? (_Subjects = new SubjectQueryableRepository(Context)); }
    }
		 
    private IQueryableFavoriteRepository _Favorites;
    public IQueryableFavoriteRepository Favorites
    {
      get { return _Favorites ?? (_Favorites = new FavoriteQueryableRepository(Context)); }
    }
		 
    private IQueryableFavoriteDerivedRepository _FavoritesDerived;
    public IQueryableFavoriteDerivedRepository FavoritesDerived
    {
      get { return _FavoritesDerived ?? (_FavoritesDerived = new FavoriteDerivedQueryableRepository(Context)); }
    }
		 
    public void Commit()
    {
      if (OwnContext)
        Context.SaveChanges();
    }

    public void Dispose()
    {
      if (OwnContext)
      {
        Context.Dispose();
        OwnContext = false;
      }
      GC.SuppressFinalize(this);
    }
  }


  public partial class DemoAppModelDataRepository : 
    IDemoAppModelDataRepository
  {
    public DemoAppModelDataRepository(DemoAppModelDbContext context)
      : this(context, false)
    {
    }

    public DemoAppModelDataRepository()
      : this(new DemoAppModelDbContext(), true)
    {
    }

    protected DemoAppModelDataRepository(DemoAppModelDbContext context, bool ownContext)
    {
      if (context == null) throw new ArgumentNullException();
      Context = context;
      OwnContext = ownContext;
    }

    protected DemoAppModelDbContext Context { get; private set; }
    protected bool OwnContext { get; private set; }

    private IRoleRepository _Roles;
    public IRoleRepository Roles
    {
      get { return _Roles ?? (_Roles = new RoleDataRepository(Context)); }
    }
		 
    private ISecurableActionRepository _SecurableActions;
    public ISecurableActionRepository SecurableActions
    {
      get { return _SecurableActions ?? (_SecurableActions = new SecurableActionDataRepository(Context)); }
    }
		 
    private IUserRepository _Users;
    public IUserRepository Users
    {
      get { return _Users ?? (_Users = new UserDataRepository(Context)); }
    }
		 
    private IPersonRepository _People;
    public IPersonRepository People
    {
      get { return _People ?? (_People = new PersonDataRepository(Context)); }
    }
		 
    private IGroupRepository _Groups;
    public IGroupRepository Groups
    {
      get { return _Groups ?? (_Groups = new GroupDataRepository(Context)); }
    }
		 
    private ISubjectRepository _Subjects;
    public ISubjectRepository Subjects
    {
      get { return _Subjects ?? (_Subjects = new SubjectDataRepository(Context)); }
    }
		 
    private IFavoriteRepository _Favorites;
    public IFavoriteRepository Favorites
    {
      get { return _Favorites ?? (_Favorites = new FavoriteDataRepository(Context)); }
    }
		 
    private IFavoriteDerivedRepository _FavoritesDerived;
    public IFavoriteDerivedRepository FavoritesDerived
    {
      get { return _FavoritesDerived ?? (_FavoritesDerived = new FavoriteDerivedDataRepository(Context)); }
    }
		 
    public void Commit()
    {
      if (OwnContext)
        Context.SaveChanges();
    }

    public void Dispose()
    {
      if (OwnContext)
      {
        Context.Dispose();
        OwnContext = false;
      }
      GC.SuppressFinalize(this);
    }
  }
}
